package com.jiantong.user.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.user.impl.dao.FeedBacksDao;
import com.jiantong.user.model.FeedBacks;
import com.jiantong.user.service.FeedBacksWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 意见反馈
 * Created by mz03 on 2017/3/23.
 * zyp
 */
@Slf4j
@Service
@RpcProvider
public class FeedBacksWriteServiceImpl implements FeedBacksWriteService{


    private final FeedBacksDao feedBacksDao;
    @Autowired
    public FeedBacksWriteServiceImpl(FeedBacksDao feedBacksDao){
        this.feedBacksDao = feedBacksDao;
    }

    /**
     * 创建一条数据
     *
     * @param feedBacks 单据对象
     * @return 主键 id
     */
    @Override
    public Response<Long> create(FeedBacks feedBacks) {
        try {
            feedBacksDao.create(feedBacks);
            return Response.ok(feedBacks.getId());
        }catch (Exception e) {
            log.error("failed.to.create.feedBacks:{}", Throwables.getStackTraceAsString(e));
            return Response.fail("create.failed");
        }
    }
}
